package com.arrays;

public class SearchInsertPosition0123_35 {
    public int searchInsert(int[] nums, int target) {

        int left = 0 , right = nums.length-1;
        while (left <= right){
            int mid = (right + left) >> 1;
            if(nums[mid] == target) return mid;
            if(nums[mid] > target) {
                right = mid - 1;
//                if(right < left) return left;
            }
            if(nums[mid] < target) {
                left = mid + 1;
//                if(right < left) return left;
            }
        }
        return left;
    }
}
